
if SERVER then
	AddCSLuaFile("shared.lua")
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false
end

if ( CLIENT ) then
	SWEP.ViewModelFOV		= 55
	SWEP.ViewModelFlip		= false
	SWEP.CSMuzzleFlashes	= false
	SWEP.Slot				= 5
	SWEP.SlotPos			= 5

	SWEP.PrintName			= "Flamethrower"			
	SWEP.IconLetter			= "C"
	SWEP.DrawAmmo = false
	SWEP.DrawCrosshair = false    
end

SWEP.Base				= "tp_base"

SWEP.Weight = 5;
SWEP.AutoSwitchTo = true;
SWEP.AutoSwitchFrom = false; 

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true

SWEP.Primary.Recoil			= 4.6
SWEP.Primary.Damage			= 10
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.02
SWEP.Primary.Delay			= .3

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "none"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"

SWEP.ViewModel			= "models/weapons/v_rpg.mdl"
SWEP.WorldModel			= "models/weapons/w_rocket_launcher.mdl"

SWEP.ShootSound = Sound("weapons/flaregun/burn.wav")

function SWEP:Initialize()
    if (SERVER) then
		self:SetWeaponHoldType("rpg")
	end
end 

function SWEP:Deploy()
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
	self:SetIronsights(false)
	local burn = Sound("fire_large") //("PhysicsCannister.ThrusterLoop")
	self.Burn = CreateSound(self.Owner, burn)
	return true
end  

function SWEP:DrawHUD()
	local w,h = ScrW(),ScrH()
	
	surface.SetDrawColor(220, 0, 0, 220)
	local wh, lh, sh = w*.5, h*.5, 10
	surface.DrawLine(wh - sh, lh - sh, wh + sh, lh - sh) //top line
	surface.DrawLine(wh - sh, lh + sh, wh + sh, lh + sh) //bottom line
	surface.DrawLine(wh - sh, lh - sh, wh - sh, lh + sh) //left line
	surface.DrawLine(wh + sh, lh - sh, wh + sh, lh + sh) //right line
end

function SWEP:FireMaker(pos)
	local fire = ents.Create( "sent_fire" )
	fire:SetPos( pos )
	fire:SetOwner( self.Owner )
	fire:Spawn()
	fire:Activate()
end

function SWEP:CanPrimaryAttack()
	return self.Delay < CurTime()
end

SWEP.TraceDelay = 0
SWEP.Delay = 0
function SWEP:PrimaryAttack()
	
	if not self:CanPrimaryAttack() then return end
	self.Delay = CurTime() + self.Primary.Delay
	
	if SERVER then
		local effectdata = EffectData()
		effectdata:SetEntity(self.Owner)
		util.Effect("flamethrower_trail", effectdata,true,true)
	end
	self.Firing = true
	if not self.Playing and SERVER then
		self.Burn:Play()
		self.Playing = true
	end
end

function SWEP:Think()
	if self.Firing then
		if self:CanPrimaryAttack() then
			self.Firing = nil
		end
		if self.TraceDelay < CurTime() then
			self.TraceDelay = CurTime() + .15
			local trace = util.GetPlayerTrace(self.Owner)
			local tr = util.TraceLine(trace)
			if (self.Owner:GetPos() - tr.HitPos):Length() > 300 then
				return
			end
			if tr.Entity:IsPlayer() and SERVER then
				if tr.Entity:Team() == TEAM_UNDEAD then
					tr.Entity:DoIgnite(self.Owner)
				end
			elseif tr.Entity:IsNPC() and SERVER then
				tr.Entity:NpcIgnite(self.Owner)
			elseif string.find(tr.Entity:GetClass(),"prop_phys") and SERVER then
				tr.Entity:TakeDamage(15,self.Owner,self.Owner)
			elseif SERVER then
				self:FireMaker(tr.HitPos + (self.Owner:GetAimVector() * -5))
			end
		end
	elseif not self.Owner:KeyDown(IN_ATTACK) then
		if SERVER then
			self.Burn:Stop()
			self.Playing = false
		end
	end
end
 
function SWEP:SecondaryAttack()

end

